<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
      /* 
            需求1：将cc替换为ss
            const str = "aabbccddffaa";
            思路：首先思考有没有现成的方法，如果有那么就直接使用，如果没有就写逻辑。
         */
        // str.replace(substr, newSubStr)，不会改变字符串本身.
        const str1 = "aabbccddffaa";
        const result = str1.replace("cc","ss");
        console.log(result);

        let str = "aabbccaaddffaa";
        str.replace("cc","ss");
        console.log(str);
        console.log("==================");

        /*  
            replaceAll
            需求2：将所有的aa替换为zz
         */
        console.log(str.replaceAll("aa","ss"));//同样不会改变字符串本身
        console.log(str);
        console.log("==================");

         /* 
            需求：提取字符串的一部分内容
            const str = "abcdefg";
         */
         const str3 = "abcdefg";
         const str4 = "abcdefg";
         const sliceStr = str3.slice(2);
         console.log(sliceStr);
         console.log(str4);
         console.log("==================");

        const str5 = 'The quick brown fox jumps over the lazy dog.';
        console.log(str5.slice(31)); //  the lazy dog.
        console.log(str5.slice(4, 19)); // quick brown fox 不包含19，到index18
        console.log(str5.slice(-4));    //dog.
        console.log(str5.slice(-9, -5)); //lazy
    </script>
</head>
<body>
    
</body>
</html>